package com.weigang.jdbctemplate.controller;

import com.weigang.jdbctemplate.entity.HrUser;
import com.weigang.jdbctemplate.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("userTest")
    public void userTest() {
        HrUser hrUser = new HrUser();
        hrUser.setAge(23);
        hrUser.setName("张三");
        //添加操作
        int i = userService.addUser(hrUser);
        System.out.println("addUser>>" + i);

        HrUser hrUser1 = new HrUser();
        hrUser1.setId(1);
        hrUser1.setName("李四");
        hrUser1.setAge(24);
        //修改操作
        int i1 = userService.updateUser(hrUser);
        System.out.println("updateUser>>" + i1);

        //获取数据
        HrUser getHrUser = userService.getUserById(1);
        System.out.println("getUserById>>" + getHrUser);

        //获取所有数据
        List<HrUser> allHrUsers = userService.getAllUsers();
        System.out.println("getAllUsers>>" + allHrUsers);

        //删除数据
        int i2 = userService.deleteUser(1);
        System.out.println("deleteUser>>" + i2);

    }

}
